package com.example.service.impl;
import com.example.dto.UserPageQuery;
import com.example.mapper.UserMapper;
import com.example.page.PageQuery;
import com.example.page.PageResult;
import com.example.po.UserPO;
import com.example.service.IUserService;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/*
@description:
@ClassName IUserServiceImpl
@author chen
@create 2025-07-15 12:25
@Version 1.0
*/
@Service
public class IUserServiceImpl implements IUserService
{
    @Resource
    private UserMapper userMapper;

    @Override
    public PageResult<UserPO> selectPage(int pageNum, int pageSize)
    {
        PageHelper.startPage(pageNum, pageSize, true);
        try
        {
            List<UserPO> users = this.userMapper.selectPage();
            return PageResult.of(users);
        } finally
        {
            // 清理分页信息
            PageHelper.clearPage();
        }
    }

    @Override
    public PageResult<UserPO> selectPageNew(int pageNum, int pageSize)
    {
        PageQuery pageQuery = PageQuery.of(pageNum, pageSize, true);
        List<UserPO> users = this.userMapper.selectPageNew(pageQuery);
        return PageResult.of(users);
    }

    @Override
    public PageResult<UserPO> userPage(UserPageQuery query)
    {
        if (StringUtils.isNotBlank(query.getKeyword()))
        {
            query.setKeyword("%" + query.getKeyword() + "%");
        }
        List<UserPO> users = this.userMapper.userPage(query);
        return PageResult.of(users);
    }
}
